// pages/fabu/fabu.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: "",
    content: "",
    uid: 0
  },
  add: function () {
    var that = this
    if (that.data.title == '') {
      wx.showToast({
        title: '请输入文章标题',
        icon: "none"
      })
      return false
    }
    if (that.data.content == '') {
      wx.showToast({
        title: '请输入文章内容',
        icon: "none"
      })
      return false
    }

    wx.request({
      url: app.data.service_url + 'wenzhang/addWenzhang',

      data: {
        uid: that.data.uid,
        title: that.data.title,
        content: that.data.content
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success(res) {
        console.log("---------------------------------------")
        console.log(res)
        if (res.data == 1) {
          wx.showToast({
            title: '发布成功',
            success(res) {
              wx.switchTab({
                url: '/pages/tabs/explore/explore',
              })
            }
          })
        } else {
          wx.showToast({
            title: '网络错误',
            icon: "error",
            success(res) {
              wx.switchTab({
                url: '/pages/tabs/explore/explore',
              })
            }
          })
        }
      }
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.getStorage({
      key: "uid",
      success(res) {
        that.setData({
          uid: res.data
        })

      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  setTitle: function (e) {
    var that = this
    //  console.log(e)
    var title = e.detail.value
    that.setData({
      title: title
    })
  },
  setContent: function (e) {
    var that = this
    // console.log(e)
    var content = e.detail.value
    that.setData({
      content: content
    })
  },
  back: function () {
    wx.switchTab({
      url: '/pages/tabs/explore/explore',
    })

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})